# Scrapy settings for bitcoin_crawler project
#
# For simplicity, this file contains only settings considered important or
# commonly used. You can find more settings consulting the documentation:
#
#     https://docs.scrapy.org/en/latest/topics/settings.html
#     https://docs.scrapy.org/en/latest/topics/downloader-middleware.html
#     https://docs.scrapy.org/en/latest/topics/spider-middleware.html
from bitcoin_crawler.utils.dir_util import create_log

BOT_NAME = 'bitcoin_crawler'

SPIDER_MODULES = ['bitcoin_crawler.spiders']
NEWSPIDER_MODULE = 'bitcoin_crawler.spiders'

# Crawl responsibly by identifying yourself (and your website) on the user-agent
# USER_AGENT = '''
# Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36
# '''

LOG_FILE = create_log()

LOG_ENABLED = True
# CRITICAL、ERROR、WARNING、INFO、DEBUG
LOG_LEVEL = 'INFO'

# Obey robots.txt rules
ROBOTSTXT_OBEY = False

# Configure maximum concurrent requests performed by Scrapy (default: 16)
CONCURRENT_REQUESTS = 250

# Configure a delay for requests for the same website (default: 0)
# See https://docs.scrapy.org/en/latest/topics/settings.html#download-delay
# See also autothrottle settings and docs
# DOWNLOAD_DELAY = 1
# RANDOM_DELAY = 1
# The download delay setting will honor only one of:
# CONCURRENT_REQUESTS_PER_DOMAIN = 16
# CONCURRENT_REQUESTS_PER_IP = 16

# Disable cookies (enabled by default)
COOKIES_ENABLED = True
COOKIES_DEBUG = True

# Disable Telnet Console (enabled by default)
# TELNETCONSOLE_ENABLED = False

# Override the default request headers:
# DEFAULT_REQUEST_HEADERS = {
#     'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
#     'Accept-Language': 'zh-CN,zh;q=0.9,zh-TW;q=0.8,en;q=0.7',
# }

# Enable or disable spider middlewares
# See https://docs.scrapy.org/en/latest/topics/spider-middleware.html
# SPIDER_MIDDLEWARES = {
#     # 'bitcoin_crawler.middlewares.BitcoinCrawlerSpiderMiddleware': 543,
#     # 'scrapy_splash.SplashDeduplicateArgsMiddleware': 100,
# }

# 设置去重过滤器
# DUPEFILTER_CLASS = 'scrapy_splash.SplashAwareDupeFilter'

# Enable or disable downloader middlewares
# See https://docs.scrapy.org/en/latest/topics/downloader-middleware.html
# DOWNLOADER_MIDDLEWARES = {
#     # 'bitcoin_crawler.middlewares.BitcoinCrawlerDownloaderMiddleware': 1,
#     # 'bitcoin_crawler.middlewares.RandomDelayMiddleware': 1,
#     # 'scrapy_splash.SplashCookiesMiddleware': 723,
#     # 'scrapy_splash.SplashMiddleware': 725,
#     # 'scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware': 810,
# }

# Enable or disable extensions
# See https://docs.scrapy.org/en/latest/topics/extensions.html
# EXTENSIONS = {
#    'scrapy.extensions.telnet.TelnetConsole': None,
# }

# Configure item pipelines
# See https://docs.scrapy.org/en/latest/topics/item-pipeline.html
ITEM_PIPELINES = {
    'bitcoin_crawler.pipelines.BitcoinCrawlerPipeline': 1,
}

# Enable and configure the AutoThrottle extension (disabled by default)
# See https://docs.scrapy.org/en/latest/topics/autothrottle.html
# AUTOTHROTTLE_ENABLED = True
# The initial download delay
# AUTOTHROTTLE_START_DELAY = 5
# The maximum download delay to be set in case of high latencies
# AUTOTHROTTLE_MAX_DELAY = 60
# The average number of requests Scrapy should be sending in parallel to
# each remote server
# AUTOTHROTTLE_TARGET_CONCURRENCY = 1.0
# Enable showing throttling stats for every response received:
# AUTOTHROTTLE_DEBUG = False

# Enable and configure HTTP caching (disabled by default)
# See https://docs.scrapy.org/en/latest/topics/downloader-middleware.html#httpcache-middleware-settings
# HTTPCACHE_ENABLED = True
# HTTPCACHE_EXPIRATION_SECS = 0
# HTTPCACHE_DIR = 'httpcache'
# HTTPCACHE_IGNORE_HTTP_CODES = []
# HTTPCACHE_STORAGE = 'scrapy.extensions.httpcache.FilesystemCacheStorage'

# 爬取网址配置
HOST = "https://bitinfocharts.com/"
CURL = """
curl 'https://bitinfocharts.com/zh/top-100-richest-bitcoin-addresses.html' \
  -H 'authority: bitinfocharts.com' \
  -H 'upgrade-insecure-requests: 1' \
  -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36' \
  -H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' \
  -H 'sec-fetch-site: none' \
  -H 'sec-fetch-mode: navigate' \
  -H 'sec-fetch-user: ?1' \
  -H 'sec-fetch-dest: document' \
  -H 'accept-language: zh-CN,zh;q=0.9,zh-TW;q=0.8,en;q=0.7' \
  -H 'cookie: __cfduid=dd2f623499e1f6fde70f723f3521987281611740623; _ga=GA1.2.706526074.1611795903; __gads=ID=b0e320069d68d215:T=1611795903:S=ALNI_MZ4sdJ-68IuqvdXL0Ydy1Qo3avTtw; _xicah=e32ae28a-afd3c0bc; _gid=GA1.2.774590109.1612142933; cf_chl_2=bdd45e3a3e7fe22; cf_chl_prog=a21; cf_clearance=cc80869a580c2ace5e7d8de1307d1e0b22159b44-1612319067-0-250' \
  --compressed
"""

# redis 配置 -> docker compose links
REDIS_HOST = 'redis'
REDIS_PORT = 6379
REDIS_DB_INDEX = 0

# splash 配置 -> docker compose links
# SPLASH_URL = 'http://splash:8050'
